VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "HttpRequest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Body_p As New HttpBody
Private Http_p As Variant
Private Boundary As String
Private PUrl_p As String

Public Property Get PUrl() As String
    PUrl = PUrl_p
End Property

Public Property Let PUrl(val As String)
    PUrl_p = val
    
     Http_p.Open "POST", PUrl, False
    '
    Http_p.setRequestHeader "Content-Type", "multipart/form-data;boundary=" & Boundary
    Http_p.setRequestHeader "Accept", "*/*"
    Http_p.setRequestHeader "Accept-Encoding", "gzip,deflate"
    Http_p.setRequestHeader "Accept-Language", "zh-CN,zh;q=0.9"
    Http_p.setRequestHeader "Cache-Control", "no-cache"
    Http_p.setRequestHeader "Connection", "keep-alive"
    Http_p.setRequestHeader "Content-Length", 0
    Http_p.setRequestHeader "Pragma", "no-cache"
    'Referer: http://192.168.9.98:8100/swagger/index.html
    Http_p.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
    Http_p.setRequestHeader "Sec-Fetch-Dest", "empty"
    Http_p.setRequestHeader "Sec-Fetch-Mode", "cors"
    Http_p.setRequestHeader "Sec-Fetch-Site", "same-origin"
End Property

Public Property Get Http() As Variant
Http = Http_p
End Property

Public Property Get Body() As Variant
Set Body = Body_p
End Property

'Public Property Get Http() As Variant
'Http = Http_p
'End Property

Public Function Send(Optional data As Variant = Nothing) As Object
    
    If data Is Nothing Then
    Dim Body As Variant
    Body = Body_p.RequestBody
        Http_p.setRequestHeader "Content-Length", Body_p.Length(Body)
        Http_p.Send Body
    Else
        If IsArray(data) Then
        Http_p.setRequestHeader "Content-Length", Body_p.Length(data)
        Else
        Http_p.setRequestHeader "Content-Length", Len(data)
        End If
        Http_p.Send data
    End If
  Set Send = Http_p
End Function

Private Sub Class_Initialize()
    Set Http_p = CreateObject("WinHttp.WinHttpRequest.5.1")
    Set Body_p = New HttpBody
    Boundary = Body_p.Boundary
   ' Set Header_p = Http_p.request
    
End Sub
